<?php

/*
 * Functions used by the simple testing framework
 */

require_once(dirname(__FILE__) . '/../../src/luminous.php');

$extra_languages = array();


$EXIT_STATUS = 0;

function test_pass_output($language, $input, $output, $expected)
{
  if (false)
  {
    echo "Passed for language $language\n";
    echo "Input:\n$input\n";
    echo "Output:\n$output\n";
    echo "Expected:\n$expected\n";
  }
  
}

function test_fail_output($language, $input, $output, $expected)
{
  global $EXIT_STATUS;
  
  echo "Failed for language $language\n";
  echo "Input:\n$input\n";
  echo "Output:\n$output\n";
  echo "Expected:\n$expected\n";
  
  $EXIT_STATUS = 1;
  
}

function test($language, $input, $output, $transform=null, $replace=null)
{
  global $luminous_grammars, $extra_languages;
  $l = new Luminous();
//   $l->SetSource($input);
  if (isset($extra_languages[$language]))
    $language = $extra_languages[$language];
  $grammar = $luminous_grammars->GetGrammar($language, false);
  
//   $l->SetGrammar($grammar);
//   $l->FinaliseSetup();
//   $l->Parse_Full();
  $out = $l->Easy_Parse($input, $grammar);
//   $out = $l->GetOutput();
  
  if ($transform !== null && $replace !== null)
  {
    $out = preg_replace($transform, $replace, $out);
  }
  
  $passed = false;
  if ($output === $out)
    $passed = true;
  
  if ($passed)
    test_pass_output($language, $input, $out, $output);
  else    
    test_fail_output($language, $input, $out, $output);
   
}
